/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aiaudio.processing.base.mapreduce.standard.reducers;

import aiaudio.processing.base.mapreduce.CoordinateDoubleValueKey;
import java.io.IOException;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.TableReducer;
import aiaudio.database.tables.RatingsMatrixTable;

/**
 *
 * @author nastya
 */
public class MatrixTransponationReducer extends TableReducer<ImmutableBytesWritable, CoordinateDoubleValueKey, ImmutableBytesWritable> {

    @Override
    protected void reduce(ImmutableBytesWritable key, Iterable<CoordinateDoubleValueKey> values, Context context) throws IOException, InterruptedException {
        Put put = new Put(key.get());

        for (CoordinateDoubleValueKey coordinateDoubleValueKey : values) {
            RatingsMatrixTable.addUserRating(put, coordinateDoubleValueKey.getCoordinate(), coordinateDoubleValueKey.getValue());
        }

        context.write(key, put);
    }
}
